from django.http import JsonResponse
from django.views import View
from housecentapp.models import Houses, HouseImg, Tags, Settings


class Housesapis(View):
    def get(self,request,*args,**kwargs):
        house = Houses.objects.get(id=kwargs["houseid"])
        houseImgs = HouseImg.objects.filter(house=house)
        tags = Tags.objects.filter(houses=house)
        settings = Settings.objects.filter(houses=house)
        showsettings=[]
        for setting in settings:
            showsettings.append(setting.name)
        showtags=[]
        for tag in tags:
            showtags.append(tag.name)
        imgs=[]
        for houseImg in houseImgs:
            imgs.append({"id":houseImg.id,"size":houseImg.size,"imgsrc":houseImg.imgsrc})

        data = {
            "tags":showtags,
            "price":house.price,
            "imgsrc":house.imgsrc,
            "placename":house.placename,
            "个人描述":house.sindecripe,
            "内部情况":house.insiposition,
            "交通情况":house.traficposition,
            "周边情况":house.arround,
            "入住须知":house.lifeknows,
            "配置情况":showsettings,
            "lat":house.lat,
            "lng":house.lng,
            "imgs":imgs,
            "city":{
                "id":house.city.id,
                "name":house.city.name,
            },
            "owner":{
                "id":house.stoge.id,
                "name":house.stoge.name
            }
        }
        return JsonResponse({"house":house.name,"data":data})
    def post(self):
        pass
    def put(self):
        pass
    def petch(self):
        pass
    def delete(self):
        pass